package part1;

public class RemoteController {
    // 开按钮的命令数组
    Command[] onCommands;
    Command[] offCommands;
    Command undoCommand;

    public RemoteController() {
        onCommands = new Command[5];
        offCommands = new Command[5];

        for (int i = 0; i < 5; i++) {
            onCommands[i] = new NoCommand();
            offCommands[i] = new NoCommand();
        }
    }

    public void setCommand(int pos, Command onCommand, Command offCommand) {
        onCommands[pos] = onCommand;
        offCommands[pos] = offCommand;
    }

    // 按下开的按钮
    public void onButtonPush(int pos) {
        onCommands[pos].execute();
        undoCommand = onCommands[pos];
    }

    public void offButtonPush(int pos) {
        offCommands[pos].execute();
        undoCommand = offCommands[pos];
    }

    public void undo() {
        undoCommand.undo();
    }
}
